home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 6024 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.8 KB

  1. Path: keats.ugrad.cs.ubc.ca!not-for-mail
  2. From: c2a192@ugrad.cs.ubc.ca (Kazimir Kylheku)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: unique id for a string
  5. Date: 21 Feb 1996 10:57:50 -0800
  6. Organization: Computer Science, University of B.C., Vancouver, B.C., Canada
  7. Message-ID: <4gfpveINNe68@keats.ugrad.cs.ubc.ca>
  8. References: <1996Feb16.175601.114182@kuhub.cc.ukans.edu> <3129dd39.961626@news.iquest.net>
  9. NNTP-Posting-Host: keats.ugrad.cs.ubc.ca
  10.  
  11. In article <3129dd39.961626@news.iquest.net>,
  12. Robert B. Clark <rclark@iquest.net> wrote:
  13.  >On 16 Feb 96 17:56:01 CST, anh@kuhub.cc.ukans.edu wrote:
  14.  >
  15.  >>HELLO =  H * 26^4 + E * 26 ^3 +  L * 26^2 + L * 26^1 + E * 26^0
  16.  >>
  17.  >>But the id is way too big. I need something that fits within a 32-bits int 
  18.  >>or a 64-bits long.
  19.  >
  20.  >You're thinking way too hard, perhaps.  Look up the algorithm for CRCs
  21.  >(cyclic redundancy checks/codes) in Snippets or most any other popular
  22.  >programmer's reference.
  23.  
  24. But he wants a _unique_ ID. This is not possible, since the space of possible
  25. words is much larger than the space of 32- or even 64-bit integers. Even for a
  26. limited dictionary of around 200,000 words, a function that _guarantees_ a
  27. unique hash for each indentifier into a 32-bit space is difficult to find.
  28.  
  29. The problem is that the poster did not give enough context about the actual
  30. problem he is trying to solve (unless this is just a homework exercise to find
  31. such a mapping). Perhaps the problem can be effectively solved without having
  32. to compute such a mapping, which is probably of little worth.
  33.  
  34. One way to get a unique mapping is to simply assign increasing numbers to the
  35. 200,000+ words, and use a hashing technique to quickly look up a word given its
  36. integer tag, and look up the tag given the word. With the proper
  37. represenatation, both operations can be done in "constant time".
  38. -- 
  39.  
  40.